/*************************************************************************
> File Name: demo.cpp
> Author: hzy
> Created Time: 2023-08-12 10:19:31
> Description:
************************************************************************/
#include <iostream>

using namespace std;

class Num
{
private:
    int val;

public:
    Num(int myval = 0) : val(myval) {}

    void show()
    {
        cout << val << endl;
    }

    friend Num operator+(Num obj1, Num obj2);
    friend Num operator++(Num &obj, int); // 后++
    friend Num operator++(Num &obj);      // 前++
};

Num operator+(Num obj1, Num obj2)
{
    Num temp;
    temp.val = obj1.val + obj2.val;

    return temp;
}

// 后++
Num operator++(Num &obj, int)
{
    Num temp = obj;
    obj.val++;

    return temp;
}

Num operator++(Num &obj)
{
    ++obj.val;

    return obj;
}

int main()
{
    Num num1(10);
    Num num2(10);
    Num num;

    num1++;         //num1:10
    num1.show();    //num1:11
    ++num2;         //num2:11
    num2.show();    //num2:11   

    num = num1 + num2;  //num: 11+11=22
    num++;              //num:22
    num.show();         //num:23

    return 0;
}